<?php

include('connection_settings.php');

//Strips " and ' marks
$bannedMarks = array("\"", "'");

$_GET['currentLanguage'] = str_replace($bannedMarks, "", $_GET['currentLanguage']);
$_COOKIE['username'] = str_replace($bannedMarks, "", $_COOKIE['username']);

//Rolls starting language one by one
if (isset($_GET['currentLanguage'])) {
 if ($_GET['currentLanguage'] == "mix") {
  $nextLanguage = "local";
 }

 elseif ($_GET['currentLanguage'] == "local") {
  $nextLanguage = "foreign";
 }

 elseif ($_GET['currentLanguage'] == "foreign") {
  $nextLanguage = "mix";
 }
 $command = "UPDATE users SET startingLanguage = '{$nextLanguage}' WHERE username = '{$_COOKIE['username']}'";
 if (!mysql_query($command)) {
  echo "<h1>Can't change the data of the table!</h1><p>" . mysql_error($connection) . "</p>";
  exit;
 }
}

echo $nextLanguage;

mysql_close($connection);

?>